C----------------------------------------------------------------------------

C  Module name: utiltest

C  Author: Gareth Williams.

C  Function: Tests the PHIGS Debugger and PHIGS view editor.

C  Dependencies:

C  Internal function list: 

C  External function list: 

C  Modification history: (Version), (Date), (name), (Description).

C  1.0, 30th October 1991, G. Williams, Translated to C.

C  2.0, June 1992, G. Williams, Converted to SunPHIGS 2.0.

C----------------------------------------------------------------------------

       PROGRAM utiltest

       include './sunphigs77.h'
       include './sunptk77.h'

C--------------------------------------------------------------------------

       INTEGER minid, maxid, white, black, green
       INTEGER grey, stid
       CHARACTER*20 commandstr
       CHARACTER*50 str
       REAL echoarea(4)
       INTEGER lencom, lenstr
       LOGICAL quit, dummy
       INTEGER stids(1)
       LOGICAL ptkf_readphinterscript
       INTEGER ptkf_stringtoint
       REAL vwormt(4, 4)
       REAL vwmpmt(4, 4)
       REAL vwcplm(6)
       INTEGER xyclpi, bclipi, fclipi
       LOGICAL docolour

       implicit undefined (P, p, E, e)
       
       print *,('Testing the utility modules of the PHIGS Toolkit...')
       print *,('Opening SunPHIGS...')

       call popph(6, 0)

C     create the workstation type (either tool or canvas) 
              
C     open the workstation 

       if (ptkf_readphinterscript('../../scripts/openws.scr', 0, 0) .eq.
& .FALSE.) then     
         goto 20
       endif

       call psdus(1, PWAITD, PNIVE)

C     define colour variable
C     for a MONOCHROME workstation set this value to .FALSE.

       docolour = .TRUE.
   
C initialise hashtables 
       minid = 1
       maxid = 300
       call ptkf_inithashtables()
       call ptkf_createhashtable('structureid', minid, maxid)
       call ptkf_createhashtable('label', minid, maxid)
       call ptkf_createhashtable('colourindex', 1, maxid)
       call ptkf_createhashtable('viewindex', 1, maxid)
       call ptkf_createhashtable('windowid', 1, maxid)
       call ptkf_createhashtable('menuid', 1, maxid)
       call ptkf_createhashtable('name', 1, maxid)
       call ptkf_createhashtable('topologyid', 1, maxid)
    
C set colours 
       if (docolour .eq. .TRUE.) then
         call ptkf_setcolourrep(1, 'black')
         call ptkf_setcolourrep(1, 'green')
         call ptkf_setcolourrep(1, 'grey')
         call ptkf_setcolourrep(1, 'white')
         call ptkf_setcolourrep(1, 'red')
         call ptkf_setcolourrep(1, 'blue')
         green = ptkf_stringtoint('colourindex', 'green')
         grey = ptkf_stringtoint('colourindex', 'grey')
         white = ptkf_stringtoint('colourindex', 'white')
         black = ptkf_stringtoint('colourindex', 'black')
         call ptkf_setbackgroundcolourind(1, grey)
         call ptkf_setdebuggerattrs(PFONTTRIPLEX, PFONTTRIPLEX,
& grey, black, grey, green, black, white, black, grey, black)
         call ptkf_setvieweditorattrs(PFONTTRIPLEX, PFONTTRIPLEX, 
&grey, black, grey, green, black, white, black, grey, black)
       endif
    
C read scripts 
       dummy = ptkf_readphinterscript('../../scripts/lamp.scr', 0, 0)
       dummy = ptkf_readphinterscript('../../scripts/postcard.scr', 
& 0, 0)
    
       stid = ptkf_stringtoint('structureid', 'lamp')
       stids(1) = stid
    
C select debugger/ view
    
        quit = .FALSE.
        call ptkf_limit(0.0, 0.25, 0.0, 0.01, echoarea)
 10     call ptkf_readstring(1, 'debugger', 
& 'Input command (default = debugger) >', echoarea, 20, commandstr, lencom) 

        if (commandstr(1:lencom) .eq. 'debugger') then
          print *,('Testing the PHIGS debugger module of the PHIGS 
& Toolkit..')
        call ptkf_readstring(1, 'lamp', 
& 'Input command (default = lamp) >', echoarea, 50, str, lenstr)
          stid = ptkf_stringtoint('structureid', str)
          call ptkf_debugger(1, stid)

        else if (commandstr(1:lencom) .eq. 'view') then
          print *,('Testing the PHIGS view editor module of the 
& PHIGS Toolkit...')
        call ptkf_readstring(1, 'lamp', 
& 'Input command (default = lamp) >', echoarea, 50, str, lenstr)
          stid = ptkf_stringtoint('structureid', str)
          call ptkf_vieweditor(1, 1, stids, vwormt, vwmpmt, vwcplm, 
& xyclpi, bclipi, fclipi)
    
       else if (commandstr(1:lencom) .eq. 'quit') then
         quit = .TRUE.

       else
          print *,('Command unknown')    
       endif

       call prst(1, PALWAY)

       if (quit .eq. .TRUE.) then
         goto 20
       else 
         goto 10
       endif

 20    call pclwk(1)
       call pclph()

       STOP
       END
    
C--------------------------------------------------------------------------
